package com.luncheng.mcp.admin.controller;

import com.luncheng.mcp.core.McpClientServer;
import io.modelcontextprotocol.client.McpSyncClient;
import io.modelcontextprotocol.spec.McpSchema;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/tools")
public class McpToolController {

    @RequestMapping("/list")
    public List<McpSchema.ListToolsResult> list() {
        Map<String, McpSyncClient> clientMap = McpClientServer.getClientMap();
        if (clientMap == null || clientMap.isEmpty()) {
            return new ArrayList<>(0);
        }
        return clientMap.values().stream().map(McpSyncClient::listTools).collect(Collectors.toList());
    }
}
